package com.reading.controller;

import com.reading.BeginTask;
import com.reading.mapper.DailyTasksMapper;
import com.reading.mapper.TaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Component
public class DatilTask {

    @Autowired
    private TaskMapper taskMapper;

    @Autowired
    private DailyTasksMapper dailyTasksMapper;

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    // 每天10点执行任务
    @Scheduled(cron = "59 59 23 * * *")
    public void executeTask() {
        System.out.println("定时任务执行时间：" + sdf.format(new Date()));
        // 调用Mapper层的方法
        taskMapper.updateAllStatus();
        dailyTasksMapper.updateAll();
    }

}
